package cn.unknowpupil.init.controller;

import java.util.List;

import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.ModelAttribute;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;

import cn.unknowpupil.init.utils.ExcelUtil;
import cn.unknowpupil.init.components.annotation.Log;
import cn.unknowpupil.init.common.enums.BusinessType;
import cn.unknowpupil.init.common.resopnse.ResultResponse;
import cn.unknowpupil.init.domain.LeaseLog;
import cn.unknowpupil.init.service.ILeaseLogService;


/**
 * Created at Tue Dec 01 09:45:21 CST 2020 by  w10g <br>
 * Initialize LeaseLogController ... <br>
 * 交租日志 视图浏览层处理
 *
 * @author  uunknowpupil
 * @since 0.0.1
 */
@Api(tags = {"交租日志模块"}, value = "leaseLog")
@RequiredArgsConstructor
@RestController
@RequestMapping("/init/log")
public class LeaseLogController {

    private final ILeaseLogService leaseLogService;

    /**
       * 分页
       *
       * @param current {@code int} 页码
       * @param size    {@code int} 笔数
       * @return {@link ResultResponse}
       */
    @ApiOperation("系统：分页交租日志")
    @GetMapping("page/{current}/{size}")
    public ResultResponse<IPage<LeaseLog>> page(@PathVariable("current") int current, @PathVariable("size") int size, @ModelAttribute LeaseLog leaseLog) {
        IPage<LeaseLog> page = leaseLogService.selectLeaseLogPages(current, size, leaseLog);
        return ResultResponse.buildSuccess(page);
    }

    /**
     * 不分页查询交租日志列表
     */
    @ApiOperation("系统：不分页查询交租日志")
    @GetMapping("/list")
    public ResultResponse list(LeaseLog leaseLog) {
        List<LeaseLog> list = leaseLogService.selectLeaseLogList(leaseLog);
        return ResultResponse.buildSuccess(list);
    }

    /**
     * 导出交租日志列表
     */
    @ApiOperation("系统：导出交租日志列表")
    @Log(title = "导出交租日志列表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResultResponse export(LeaseLog leaseLog) {
        List<LeaseLog> list = leaseLogService.selectLeaseLogList(leaseLog);
        ExcelUtil<LeaseLog> util = new ExcelUtil<LeaseLog>(LeaseLog. class);
        String fileName = util.exportExcel(list, "交租日志");
        return ResultResponse.buildSuccess(fileName);
    }

    /**
     * 获取交租日志详细信息
     */
            @ApiOperation("系统：获取交租日志详细信息")
    @GetMapping(value = "/{id}")
    public ResultResponse getInfo(@PathVariable("id") Long id) {
        return ResultResponse.buildSuccess(leaseLogService.selectLeaseLogById(id));
    }

    /**
     * 新增交租日志
     */
            @Log(title = "交租日志", businessType = BusinessType.INSERT)
    @ApiOperation("系统：新增交租日志")
    @PostMapping
    public ResultResponse add(@RequestBody LeaseLog leaseLog) {
        return ResultResponse.buildSuccess(leaseLogService.insertLeaseLog(leaseLog));
    }

    /**
     * 修改交租日志
     */
            @ApiOperation("系统：修改交租日志")
    @Log(title = "修改交租日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultResponse edit(@RequestBody LeaseLog leaseLog) {
        return ResultResponse.buildSuccess(leaseLogService.updateLeaseLog(leaseLog));
    }

    /**
     * 删除交租日志
     */
            @ApiOperation("系统：删除交租日志")
    @Log(title = "删除交租日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResultResponse remove(@PathVariable Long[] ids) {
        return ResultResponse.buildSuccess(leaseLogService.deleteLeaseLogByIds(ids));
    }
}
